package com.tql.mall.boss.controller.boss;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tql.mall.boss.service.BaseTrademarkService;
import com.tql.mall.common.result.R;
import com.tql.mall.model.product.BaseTrademark;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(description = "品牌标签接口")
@RestController
@RequestMapping("/boss/boss/trademark")
public class TrademarkController {

    @Autowired
    private BaseTrademarkService baseTrademarkService;

    @ApiOperation("根据商标id获取BaseTrademark对象")
    @GetMapping("/getTrademarkById/{id}")
    public R<BaseTrademark> getTrademarkById(@PathVariable Long id){
        BaseTrademark baseTrademark = baseTrademarkService.getById(id);
        return R.ok(baseTrademark);
    }

    @ApiOperation("获取所有的品牌列表")
    @GetMapping("/getTrademarkList")
    public R<List<BaseTrademark>> getTrademarkList(){
        List<BaseTrademark> list =  baseTrademarkService.getTrademarkList();
        return R.ok(list);
    }



    /**
     * admin/product/baseTrademark/{page}/{limit}
     * 品牌分页列表查询
     * @param page
     * @param limit
     * @return
     */
    @GetMapping("{page}/{limit}")
    public R<IPage<BaseTrademark>> getBaseTrademakrPage(@PathVariable Long page,
                                       @PathVariable Long limit){

        //封装分页对象
        Page<BaseTrademark> baseTrademarkPage=new Page<>(page,limit);
        IPage<BaseTrademark> baseTrademarkIPage=baseTrademarkService.getBaseTrademakrPage(baseTrademarkPage);
        return R.ok(baseTrademarkIPage);

    }


    /**
     * 保存
     * admin/product/baseTrademark/save
     * @param baseTrademark
     * @return
     */
    @PostMapping("/save")
    public R<Void> save(@RequestBody BaseTrademark baseTrademark){
        baseTrademarkService.save(baseTrademark);
        return R.ok();
    }


    /**
     * 修改品牌
     * admin/product/baseTrademark/update
     * @param baseTrademark
     * @return
     */
    @PutMapping("/update")
    public R<Void> update(@RequestBody BaseTrademark baseTrademark){
        baseTrademarkService.updateById(baseTrademark);
        return R.ok();
    }


    /**
     * admin/product/baseTrademark/get/{id}
     * 根据品牌Id 回显品牌数据 --- 获取详情
     * @param id
     * @return
     */
    @GetMapping("/get/{id}")
    public R<BaseTrademark> get(@PathVariable Long id){
        BaseTrademark baseTrademark = baseTrademarkService.getById(id);
        return R.ok(baseTrademark);
    }


    /**
     * admin/product/baseTrademark/remove/{id}
     * 根据id删除品牌
     * @param id
     * @return
     */
    @DeleteMapping("/remove/{id}")
    public R<Void> remove(@PathVariable Long id ){
        baseTrademarkService.removeById(id);
        return R.ok();
    }


}
